package com.company;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class Solution {
    public boolean isValid(String s) {
        HashMap<Character, Character> map = new HashMap<Character, Character>();
        map.put(')', '(');
        map.put('}', '{');
        map.put(']', '[');
        Stack<Character> chars = new Stack<Character>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (map.containsKey(c)) {
                char pop = chars.isEmpty() ? '#' : chars.pop();
                if (pop != map.get(c)) {
                    return false;
                }
            } else {
                chars.push(c);
            }
        }

        return chars.isEmpty();

    }

    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[j] + nums[i] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[0];
    }

    public int[] twoSum1(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                return new int[]{map.get(target - nums[i]), i};
            } else {
                map.put(i, nums[i]);
            }
        }
        return new int[0];
    }

    /*   回文  xiaohutu  2020/12/21  15:47    */
    public boolean isPalindrome(int x) {

        String s = x + "";
        String[] split = s.split("");
//        Stack<String> strings = new Stack<>();
        boolean flag = true;
        for (int i = 0; i < (split.length / 2) + 1; i++) {
            if (!split[i].equals(split[split.length - 1 - i])) {
                flag = false;
            }
        }
        return flag;
    }

    public String longestCommonPrefix(String[] strs) {
        for (String str : strs) {

        }
        return "";
    }


    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.longestCommonPrefix(new String[]{"flower", "flow", "flight"}));
//        System.out.println(solution.twoSum1(new int[]{2, 7, 11, 15}, 9).toString());
//        boolean valid = solution.isValid("()");
//        System.out.println(valid);
    }
}
